/***************************************************************************
 *   Copyright (C) 2009 by maarten,,,   *
 *   maarten@maarten-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef SCENEPOINTLIGHT_H
#define SCENEPOINTLIGHT_H

#include "scenemanager/sceneelement.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;

#include "objects/vertex.h"

namespace scene {

/**
    @author maarten,,, <maarten@maarten-laptop>
*/
class PointLight : public SceneElement
{
public:
    PointLight();
    ~PointLight();

    void printElement();

    inline void setColor ( object::Vertex* theValue )
    {
        m_color = theValue;
    }

    inline object::Vertex* color() const
    {
        return m_color;
    }
    
    inline void setPos ( object::Vertex* theValue )
    {
        m_pos = theValue;
        
    }

    inline object::Vertex* pos() const
    {
        return m_pos;
    }
    
    inline void setIntensity(float val){
      m_intensity = val;
    }
    
    inline float intensity(){return m_intensity;}
    
    // surface functions
    inline void setAlpha(object::Vertex * val){m_alpha = val;}
    inline void setBeta(object::Vertex * val){m_beta = val;}
    inline void setSurfacePos(object::Vertex * val){m_surfacePos =
val;m_surface = true;}
    
    inline void regenerate()
    { 
      // generate random i & j
      float i = rand() % (int)m_surfaceFactor;
      float j = rand() % (int)m_surfaceFactor;
      
      //cout << "generated:" << i << ", " << j << endl;
              
      m_pos->setX(m_surfacePos->x() + m_rowX*i + m_colX*j);
      m_pos->setY(m_surfacePos->y() + m_rowY*i + m_colY*j);
      m_pos->setZ(m_surfacePos->z() + m_rowZ*i + m_colZ*j);
      m_pos->setH(1);
    };
    
    inline bool isSurface(){return m_surface;}
    inline int surfaceFactor(){return (int)m_surfaceFactor;}
    
    inline void setrowX(float val){m_rowX = val;}
    inline void setrowY(float val){m_rowY = val;}
    inline void setrowZ(float val){m_rowZ = val;}
    
    inline void setcolX(float val){m_colX = val;}
    inline void setcolY(float val){m_colY = val;}
    inline void setcolZ(float val){m_colZ = val;}
    inline void setSurfaceFactor(float val){m_surfaceFactor = val;}

private:
    object::Vertex *m_color;
    object::Vertex *m_pos;
    float m_intensity;
    
    
    bool m_surface;
    object::Vertex * m_alpha;
    object::Vertex * m_beta;
    object::Vertex * m_surfacePos;
    
    float m_rowX;
    float m_rowY;
    float m_rowZ;
    
    float m_colX;
    float m_colY;
    float m_colZ;
    
    float m_surfaceFactor;
};

}

#endif